home *** CD-ROM | disk | FTP | other *** search
/ Qoole for Quake / Qoole for Quake (USA) / Qoole for Quake (USA).bin / Tutorial / HTML / QUBE.ZIP / SRC / SCRN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-05  |  6.2 KB  |  311 lines

  1.  
  2. #include "bsp5.h"
  3. #include "curs.h"
  4. #include <stdarg.h>
  5. #include <signal.h>
  6.  
  7. int             StatusLine;             /* Output line for status info */
  8. long int    StartTime;
  9. long int    LastCheck;
  10. int        TotalStatusEntries;    /* How many status entries have gone by (out of 32) */
  11. int        CurPercent;
  12. int        CurMajorPercent;
  13.  
  14. long int    TotalAlloc = 0L;
  15. long int    LastAlloc = 0L;     /* To keep speed up */
  16.  
  17. void ScrnShutDown(void)
  18. {
  19.     long int now = (long)I_FloatTime ();
  20.     long int diff = now - StartTime;
  21.  
  22.     fflush(stdout);
  23.  
  24.         InitText();
  25.     if (LogFile != NULL) {
  26.         fflush(LogFile);
  27.         fclose(LogFile);
  28.         }
  29.  
  30.     printf("Ctrl+C hit.  Aborting compile after %02ld:%02ld:%02ld.\n",
  31.         diff / 360, (diff / 60) % 59, diff % 59, TotalAlloc);
  32.     fflush(stdout);
  33.  
  34.     exit(-1);
  35. }
  36.  
  37. void ScrnInit(void)
  38. {
  39.         InitText();
  40.  
  41.     signal(SIGINT, ScrnShutDown);
  42.     signal(SIGQUIT, ScrnShutDown);
  43.  
  44.     LastCheck = StartTime = (long)I_FloatTime ();
  45.  
  46.         SetForeColor(ANSI_WHITE);
  47.     SetBackColor(ANSI_BLUE);
  48.     DrawFilledBox(0,0, ScrnWidth,ScrnHeight);
  49.  
  50.     CurPercent = CurMajorPercent = -1;
  51.         StatusLine = 5;
  52.         
  53.     MoveCurs(2, 1);
  54.     SetForeColor(ANSI_WHITE);
  55.     SetBackColor(ANSI_BLUE);
  56.     DrawVLine(45, 5, ScrnHeight-6);
  57.     DrawHLine(1,4, ScrnWidth-2);
  58.     MoveCurs(2, 3);
  59.     CPrintf("$f3Elapsed time: $f200:00:00       $f30 $f7Kbytes $f4--------------------------------------$f3");
  60.     MajorPercentBar(0);
  61.         PercentBar(0);
  62. }
  63.  
  64. void ShowStatusEntry(char *format, ...)
  65. {
  66.     char text[1024];
  67.     va_list v;
  68.  
  69.     va_start(v, format);
  70.     vsprintf(text, format, v);
  71.  
  72.     SetBackColor(ANSI_BLUE);
  73.     SetForeColor(ANSI_WHITE);
  74.  
  75.         if (StatusLine > ScrnHeight-2) {
  76.         CopyText(2, 8, 42, ScrnHeight-9, 2, 7);
  77.         FillBox(1, ScrnHeight-2, 42, 1, ' ');
  78.         StatusLine--;
  79.         }
  80.  
  81.         MoveCurs(2, StatusLine);
  82.     CPrintf("%s", text);
  83.  
  84.     if (LogFile != NULL)
  85.         CfPrintf(LogFile, "%s", text);
  86.  
  87.         StatusLine++;
  88.  
  89.         PrintBSPFileSizes();
  90.     TimeUpdate();
  91. }
  92.  
  93. void ShowTempEntry(char *format, ...)
  94. {
  95.     char text[1024];
  96.     va_list v;
  97.  
  98.     va_start(v, format);
  99.     vsprintf(text, format, v);
  100.  
  101.     SetBackColor(ANSI_BLUE);
  102.  
  103.         if (StatusLine > ScrnHeight-2) {
  104.         SetForeColor(ANSI_WHITE);
  105.         CopyText(2, 8, 42, ScrnHeight-9, 2, 7);
  106.         FillBox(1, ScrnHeight-2, 42, 1, ' ');
  107.         StatusLine--;
  108.         }
  109.  
  110.         SetForeColor(ANSI_GREEN);
  111.  
  112.     MoveCurs(4, StatusLine);
  113.     CPrintf("%s", text);
  114.  
  115.     if (LogFile != NULL)
  116.         CfPrintf(LogFile, "$t%s", text);
  117.  
  118.     StatusLine++;
  119.  
  120.     PrintBSPFileSizes();
  121.     TimeUpdate();
  122. }
  123.  
  124. void ShowWarningEntry(char *format, ...)
  125. {
  126.     char text[1024];
  127.     va_list v;
  128.  
  129.     va_start(v, format);
  130.     vsprintf(text, format, v);
  131.  
  132.     SetBackColor(ANSI_BLUE);
  133.  
  134.         if (StatusLine > ScrnHeight-2) {
  135.         SetForeColor(ANSI_WHITE);
  136.         CopyText(2, 8, 42, ScrnHeight-9, 2, 7);
  137.         FillBox(1, ScrnHeight-2, 42, 1, ' ');
  138.         StatusLine--;
  139.         }
  140.  
  141.     SetForeColor(ANSI_RED);
  142.  
  143.     MoveCurs(4, StatusLine);
  144.     CPrintf("$f1*** %s", text);
  145.  
  146.     if (LogFile != NULL)
  147.         CfPrintf(LogFile, "*** %s", text);
  148.  
  149.     StatusLine++;
  150.  
  151.     PrintBSPFileSizes();
  152.     TimeUpdate();
  153. }
  154.  
  155. void PercentBar(int percent)
  156. {
  157.         if (percent > 256) percent = 256;
  158.  
  159.         if (percent != CurPercent) {
  160.         int n = (percent * 38) / 256;
  161.  
  162.         SetBackColor(ANSI_BLUE);
  163.         SetForeColor(ANSI_GREEN);
  164.         FillBox(40, 3, n, 1, '#');
  165.         SetForeColor(ANSI_BLUE);
  166.         FillBox(40+n, 3, 38-n, 1, '-');
  167.  
  168.                 CurPercent = percent;
  169.         }
  170.         TimeUpdate();
  171. }
  172.  
  173. void MajorPercentBar(int percent)
  174. {
  175.     if (percent > 256) percent = 256;
  176.  
  177.         if (percent != CurMajorPercent) {
  178.         int n = (percent * 76) / 256;
  179.  
  180.         SetBackColor(ANSI_BLUE);
  181.         SetForeColor(ANSI_GREEN);
  182.         FillBox(2, 2, n, 1, '#');
  183.         SetForeColor(ANSI_BLUE);
  184.         FillBox(2+n, 2, 76-n, 1, '-');
  185.  
  186.                 CurMajorPercent = percent;
  187.         }
  188.  
  189.         TimeUpdate();   
  190. }
  191.  
  192. void TimeUpdate(void)
  193. {
  194.     long int now = (long)I_FloatTime ();
  195.  
  196.     if (now != LastCheck) {
  197.         long int diff = now - StartTime;
  198.  
  199.         if (diff > 0) {
  200.             MoveCurs(16, 3);
  201.             CPrintf("$f2%02ld:%02ld:%02ld $f3%7ld$f7 Kbytes", diff / 360, (diff / 60) % 59, diff % 59, TotalAlloc/1024L);
  202.         }
  203.         LastCheck = now;
  204.         }
  205. }
  206.  
  207. void CfPrintf(FILE *file, char *format, ...)
  208. {
  209.     register char c;
  210.     register char *ptr, *src;
  211.         char text[1024];
  212.     char text2[1024];
  213.         va_list v;
  214.  
  215.     va_start(v, format);
  216.     vsprintf(text, format, v);
  217.  
  218.     for (ptr = text2, src = text; *src != '\0'; src++) {
  219.         c = *src;
  220.  
  221.         if (c == '$') {
  222.             switch (*++src) {
  223.             case '$':
  224.                 *ptr++ = '$';
  225.                                 break;
  226.                         case 'a':
  227.                 *ptr = '\0';
  228.                 fputs(ptr = text2, file);
  229.                                 break;
  230.             case 't':
  231.                 *ptr = '\0';
  232.                 cputs(ptr = text2);
  233.                 fputs("\t", file);
  234.                                 break;
  235.                         case 'n':
  236.                 *ptr = '\0';
  237.                 cputs(ptr = text2);
  238.                 fputs("\n", file);
  239.                                 break;
  240.             case 'f':
  241.                 *ptr = '\0';
  242.                 fputs(ptr = text2, file);
  243.                                 ++src;
  244.                                 break;
  245.             case 'b':
  246.                 *ptr = '\0';
  247.                 fputs(ptr = text2, file);
  248.                                 ++src;
  249.                 break;
  250.             case 'c':
  251.                 *ptr = '\0';
  252.                 fputs(ptr = text2, file);
  253.                 ++src;
  254.                 break;
  255.                         }
  256.                 }
  257.         else if (c >= 32 && c <= 126)
  258.             *ptr++ = c;
  259.     }
  260.     *ptr = '\0';
  261.     fputs(ptr = text2, file);
  262.     fputs("\n", file);
  263.  
  264.     fflush(file);
  265. }
  266.  
  267. void *qmalloc(int size)
  268. {
  269. #undef malloc
  270.     int total = size + sizeof(int);
  271.     void *mem = malloc(total);
  272.     long int diff;
  273.  
  274.     if (mem == NULL)
  275.         Error("Insufficient memory.");
  276.  
  277.     *((int *)mem) = size+sizeof(int);
  278.     TotalAlloc += total;
  279.  
  280.     diff = TotalAlloc - LastAlloc;
  281.     if (diff < 0L) diff = -diff;
  282.     if (diff > 131072L) {
  283.         LastAlloc = TotalAlloc;
  284.         LastCheck = -1L;
  285.                 TimeUpdate();
  286.         }
  287.  
  288.         return(mem + sizeof(int));
  289. }
  290.  
  291. void qfree(void *mem)
  292. {
  293. #undef free
  294.     long int diff;
  295.  
  296.         mem -= sizeof(int);
  297.  
  298.     TotalAlloc -= *((int *)mem);
  299.  
  300.     diff = TotalAlloc - LastAlloc;
  301.     if (diff < 0L) diff = -diff;
  302.     if (diff > 131072L) {
  303.         LastAlloc = TotalAlloc;
  304.         LastCheck = -1L;
  305.                 TimeUpdate();
  306.         }
  307.  
  308.         free(mem);
  309. }
  310.  
  311.